package GeoLocation::BaiduMapReverseGeocoder;

use strict;
use warnings;
use 5.010;

use Mojo::UserAgent;
use Utils::Constants;

sub new {
    my $class = shift;
    my $self = {};

    bless $self, $class;

    return $self;
}

sub reverse_geocode {
    my $self = shift;
    my $geolocation = shift;
    my $ua = Mojo::UserAgent->new;
    my $ak = Utils::Constants::BAIDU_MAP_API_ACCESSKEY;
    my $address_desc = $ua->get("http://api.map.baidu.com/geocoder/v2/?ak=$ak&location=$geolocation&output=xml")
                            ->res->dom->at('formatted_address')->text;
    
    return defined $address_desc ? $address_desc : '';
}

1;
